import {get, post, put} from "@/utils/request";
import {AxiosPromise} from "@/types/common";
import {IPreviewParams} from "@/types/generator";
import {ITableDefaultData, PreviewVO} from "@/types/table";

/**
 * 根据表 ID 获取表信息
 * @param id 表 ID
 */
export const useTableApi = (id: number): AxiosPromise<any> => {
    return get('/generator/v1/table/' + id)
}

/**
 * 表单数据修改
 * @param dataForm 表单数据
 */
export const useTableSubmitApi = (dataForm: any) => {
    return put('/generator/v1/table', dataForm)
}

/**
 * 根据数据源导入数据库表列表
 * @param datasourceId 数据源 ID
 * @param tableNameList 表名列表
 */
export const useTableImportSubmitApi = (datasourceId: string, tableNameList: string[]) => {
    return post('/generator/v1/table/import', {
        datasourceId: datasourceId,
        tableNameList: tableNameList
    })
}

/**
 * 修改字段数据
 * @param tableId 表 ID
 * @param fieldList 子弹列表
 */
export const useTableFieldSubmitApi = (tableId: number, fieldList: any) => {
    return put('/generator/v1/table/field/' + tableId, fieldList)
}

/**
 * 文件预览
 * @param params 预览参数
 */
export const useTablePreviewApi = (params: IPreviewParams): AxiosPromise<PreviewVO> => {
    return post('/generator/v1/table/preview', params)
}

/**
 * 获取默认的数据
 */
export const useTableDefaultDataApi = (): AxiosPromise<ITableDefaultData> => {
    return get('/generator/v1/table/default')
}
